#ifndef NINTERFACESIMALGADD_H
#define NINTERFACESIMALGADD_H

#include <QtSql>
#include "ninterfacealgadd.h"

//реализация интерфейсов (одна из возможных;)

class IAlgorithmAddImpl : public IAlgorithmAdd     //добавление алгоритма
{
public:
    IAlgorithmAddImpl() { }

    //методы!
    QByteArray addNewAlgorithm(QString settsBaseDir, QString settsCompiler, QByteArray algCode, QString binAlgName, QString codeAlgName)      //компиляция и создание бинарного кода
    {
        QFile fileTmpl(settsBaseDir + QString("template.cpp"));
        fileTmpl.open(QIODevice::ReadOnly);
        QByteArray algBaseCode = fileTmpl.readAll();
        fileTmpl.close();

        algBaseCode = algBaseCode.replace("%ALG_CODE%", algCode);
        QFile fileTmpl2(settsBaseDir+codeAlgName);
        fileTmpl2.open(QIODevice::WriteOnly);
        fileTmpl2.write(algBaseCode);
        fileTmpl2.close();

        QProcess process;
        process.start(settsCompiler + QString(" ") + settsBaseDir + codeAlgName + QString(" -o ") + settsBaseDir + binAlgName);
        process.waitForFinished();

        //qDebug("cmd: |%s|", (settsCompiler + tr(" ") + settsBaseDir + tr("template.cpp -o ") + settsBaseDir + binAlgName).toLocal8Bit().data());
        //qDebug("workdir: |%s|", process.workingDirectory().toLocal8Bit().data());

        QFile::remove(settsBaseDir+codeAlgName);

        return process.readAllStandardError();//.readAllStandardOutput();
        //qDebug("build res: |%s|", result.data());
    }

    ~IAlgorithmAddImpl() { }
};


#endif
